package com.siwei.mes.entity.laboratory.sync;

import com.siwei.mes.entity.materials.MaterialsSpecConfig;
import com.siwei.mes.enums.MaterialsEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

/**
 * 同步协会软件原材料实体类
 *
 * @Description: 同步协会软件原材料实体类
 * @Version: 1.0
 * @author: mlchen
 * @date: 2024/6/24 00:32
 */
@Data
@Accessors(chain = true)
public class SyncLaboratoryMaterialsInfo {
    @ApiModelProperty(value = "原材料名称")
    private String materialsName;

    @ApiModelProperty(value = "原材料简称")
    private String materialsAbbreviation;

    @ApiModelProperty(value = "规格")
    private String specName;

    @ApiModelProperty(value = "规格内容")
    private String gradeName;
    /**
     * 1-水泥 2-粉煤灰 3-矿渣粉 4-粗骨料 5-细骨料 6-外加剂 7-混凝土
     */
    @ApiModelProperty(value = "原材料类型")
    private Integer materialsType;

    @ApiModelProperty(value = "协会sampleId")
    private String sampleId;

    @ApiModelProperty(value = "协会specId")
    private String specId;

    @ApiModelProperty(value = "协会gtadeId")
    private String gradeId;

    @ApiModelProperty(value = "协会试验依据")
    private String sampleJudge;


    /**
     * 组装材料信息
     *
     * @param entity
     * @param isAppendGradeName 是否需要拼接gradeName  true-需要  false-不需要
     * @return
     */
    public static MaterialsSpecConfig payloadMaterials(SyncLaboratoryMaterialsInfo entity, boolean isAppendGradeName) {
        if (entity.getMaterialsType() == null) {
            return null;
        }
        MaterialsSpecConfig config = new MaterialsSpecConfig();
        config.setIsLaboratory(1);
        config.setMaterialsName(entity.getMaterialsName());

        String specName = StringUtils.isBlank(entity.getSpecName()) ? "" : entity.getSpecName();

        String gradeName = StringUtils.isBlank(entity.getGradeName()) ? "" : entity.getGradeName();

        /**如果是混凝土的 不需要拼规格*/
        if (entity.getMaterialsType().equals(MaterialsEnum.CONCRETE.getCode())) {
            config.setMaterialsSpec(gradeName);
        } else {
            /**这里处理一下如果规格和gradeName都为空的情况  如果两个都为空 直接赋值材料名称*/
            if (StringUtils.isBlank(specName) && StringUtils.isBlank(gradeName)) {
                config.setMaterialsSpec(entity.getMaterialsName());
            } else {
                /**这里判断是否需要拼接gradeName*/
                if (isAppendGradeName) {
                    config.setMaterialsSpec(specName + gradeName);
                } else {
                    config.setMaterialsSpec(specName);
                }
            }
        }
        config.setMaterialAbbreviation(entity.getMaterialsAbbreviation());
        config.setMaterialsType(entity.getMaterialsType());
        config.setSampleId(entity.getSampleId());
        config.setSampleName(entity.getMaterialsName());
        config.setSpecId(entity.getSpecId());
        config.setSpecName(entity.getSpecName());
        config.setGradeId(entity.getGradeId());
        config.setGradeName(entity.getGradeName());
        config.setSampleJudge(entity.getSampleJudge());
        return config;
    }
}
